import { USER_IS_LOGIN } from "../mutation_types";

const state = {
  isLogin: false, // 是否登录
  cartList: [],
};

const mutations = {
  // 是否登录
  [USER_IS_LOGIN]: (state, value) => {
    // 是否登录 交给是否有token
    let userInfo = uni.getStorageSync("userInfo") || {};
    state.isLogin = !!userInfo?.token;
  },
  setLoginState: (state, value) => {
    state.isLogin = value;
  },
  setCardList(state, data) {
    state.cartList = data;
  },
};

const actions = {
  set_change_is_login({ commit }, value) {
    commit(USER_IS_LOGIN, value);
  },
  handleSetCardList({ commit }, pyload) {
    commit("setCardList", pyload);
  },
};

export default {
  state,
  mutations,
  actions,
};
